#include "user.h"


/* Setters */
void SetUserName(User * NewUser, char * NewUserName)
{
	NewUser->userName = NewUserName;
}

void SetID(User * NewUser, int NewID)
{
	NewUser->id = NewID;
}

void SetSocket(User * NewUser, SOCKET NewSock)
{
	NewUser->sock = NewSock;
}

void SetSin(User * NewUser, SOCKADDR_IN NewSin)
{
	NewUser->sin = NewSin;
}

void SetIP(User * NewUser, char * IP)
{
	NewUser->sin.sin_addr.s_addr = inet_addr(IP);
}


/* Getters */
char * GetUserName(User NewUser)
{
	return NewUser.userName;
}

int GetID(User NewUser)
{
	return NewUser.id;
}

SOCKET GetSocket(User NewUser)
{
	return NewUser.sock;
}

SOCKADDR_IN GetSin(User NewUser)
{
	return NewUser.sin;
}

char * GetIP(User NewUser)
{
	return inet_ntoa(NewUser.sin.sin_addr);
}



void UserTestRegression()
{
	printf("\n\n\nTestRegression du module User :\n\n");
	
	/* Initialisation d'un username, d'un id */
	char * name = "Pepito";
	int id = 4939;
	
	/* Initialisation d'un socket */
	SOCKET sock = socket(AF_INET, SOCK_STREAM, 0);
	
	/* Initialisation d'un sin */
	SOCKADDR_IN sin;
	sin.sin_addr.s_addr = htonl(INADDR_ANY);
   	sin.sin_family = AF_INET;
   	sin.sin_port = htons(PORT);
   	
   	/* Test des Getter/Setter */
   	User NewUser;
   	SetUserName(&NewUser, name);
   	SetID(&NewUser, id);
   	SetSocket(&NewUser, sock);
   	SetSin(&NewUser, sin);
   	
   	if (GetUserName(NewUser) == name)
   	{
   		printf("\nSetUserName et GetUserName...OK !");
   	}
   	else
   	{
   		printf("\nSetUserName et/ou GetUserName...Erreur !");
   	}
   	
   	if (GetID(NewUser) == id)
   	{
   		printf("\nSetID et GetID...OK !");
   	}
   	else
   	{
   		printf("\nSetID et/ou GetID...Erreur !");
   	}
   	
   	if (GetSocket(NewUser) == sock)
   	{
   		printf("\nSetSocket et GetSocket...OK !");
   	}
   	else
   	{
   		printf("\nSetSocket et/ou GetSocket...Erreur !");
   	}
   	
   	if (inet_ntoa(GetSin(NewUser).sin_addr) == inet_ntoa(sin.sin_addr))
   	{
   		printf("\nSetSin et GetSin...OK !");
   	}
   	else
   	{
   		printf("\nSetSin et/ou GetSin...Erreur !");
   	}
}
